package cn.thoughtworks.school.configrations;

import cn.thoughtworks.school.resolvers.AuthResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.List;

@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        argumentResolvers.add(new AuthResolver());
    }
  @Bean
  PermissionInterceptor permissionInterceptor(){
    return new PermissionInterceptor();
  }


  @Override
  public void addInterceptors(InterceptorRegistry registry) {

    //添加拦截器
    registry.addInterceptor(permissionInterceptor())
      .addPathPatterns("/**");
    super.addInterceptors(registry);
  }
}
